
#include "PreHeader.h"
#include "cBullet.h"

cBullet::cBullet()
{
	m_bulletType = eBulletType::NORMAL;
}

cBullet::~cBullet()
{

}

void cBullet::Init(const sBulletDesc& desc)
{
	cEntity::Init(desc.entityDesc);

	m_sprite->setScale(1.5f);

	m_bulletType = desc.bulletType;
}

void cBullet::Update(float dt)
{
	cEntity::Update(dt);

	CCSize screenSize = CCDirector::sharedDirector()->getWinSize();

	switch (m_bulletType)
	{
	case eBulletType::NORMAL:
	//case eBulletType::PIERCE:
		{
			const b2Vec2& bodyPos = m_body->GetPosition();
			CCPoint pos = ccp(bodyPos.x*PTM_RATIO, bodyPos.y*PTM_RATIO);
			if (pos.x < 0.0f || pos.x > screenSize.width || pos.y > screenSize.height)
			{
				m_deleted = true;
			}
		}
		break;
	}
}

void cBullet::OnHit()
{
	switch (m_bulletType)
	{
	case eBulletType::NORMAL:
		{
			m_deleted = true;
		}
		break;
	}
}

//void cBullet::Move(const CCPoint& posv)
//{
//	SetPosv(posv);
//}